package finalgame.Engine.trainer;
import finalgame.Util;
import finalgame.Engine.weakness;
import finalgame.Engine.pokemon.*;
import finalgame.Engine.moves.*;
public class trainerAI {
	
	public static Pokemon selectPokemon(Trainer trainer, Pokemon opponentPokemon){
		Pokemon[] pokemonlist = trainer.getPokemonInventory();
		int numofpokemon = trainer.getNumberOfPokemon();
		Pokemon selectedpokemon = null;
		for(int i = 0; i < trainer.getNumberOfPokemon();i++){
			if(pokemonlist[i].getHP()>0){
				selectedpokemon = pokemonlist[i];
				trainer.switchPokemon(i);
			}
		}
		int typeToLookFor = weakness.getweakness(opponentPokemon.getType());
		
		//loops through the trainer inventory to see if they have the type they are looking for
		for(int i = 0; i<trainer.getNumberOfPokemon();i++){
			if(pokemonlist[i].getType() == typeToLookFor && pokemonlist[i].getHP()>0){
				selectedpokemon = pokemonlist[i];
				trainer.switchPokemon(i);
				break;
			}
		}
		return selectedpokemon;
	}
	
	public static Move selectMove(Pokemon currentPokemon, Pokemon opponentPokemon){
		String[] moves = currentPokemon.getMoves();
		String movetoUse = moves[0];
		int TypetoLookFor = weakness.getweakness(opponentPokemon.getType());
		
		for(int i = 0; i<Util.getSize(moves); i++){
			if(Move.getNewMove(moves[i]).getAttacktype() == TypetoLookFor){
				return Move.getNewMove(moves[i]);
			}
		}
		//select a random move
		return Move.getNewMove(moves[randomNumber(Util.getSize(moves))]);
		
	}
	
	private static int randomNumber(){
		return randomNumber(4);
	}
	
	private static int randomNumber(int max){
		return (int) (Math.random()*max);
	}
}
